home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
utter10.zip
/
UTTER.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1994-06-20
|
36KB
|
917 lines
PROGRAM Utter;
(* UTTER 1.0, Copyright (c) 1994, by Jody R. Cairns
UTTER displays quotes that are stored in a separate ASCII data file, by
default called UTTER.DAT, although a different file can be used if
specified on the command-line. All quotes must end with a tilde (~).
The quote file may be edited using the /E option. There are many more
options (and more to come) including: display random quote, prompt
user after quote is displayed, change video output, show number of
quotes in quote file, etc.
The source to this program (this file) is free to the public domain with
the condition that I am notified of any modifications made to this
program, and the executable of the MODIFIED program is NOT distributed
without my permission (i.e. Don't pull a fast one like making a few
changes to the source, compiling it, and saying you wrote it.). Otherwise,
the source and executable are free to those who want it.
It would be very much appreciated if any code used from this program is
credited to me (bearing in mind that I take absolutely no responsibility
for the results or misuse of the execution or use of said code).
Main Algorithm
--------------
1) Check if valid DOS version (must be >= 3.0).
2) Get executable's filename and residing directory.
3) Process command-line for options.
4) Check if data file containing quotes exists.
5) Check if index file for data file exists and is valid.
6) Read index file to get old data file time-stamp.
7) Compare old data file's time-stamp with current data file's time-stamp.
8) Update index file if any discrepancies.
9) Execute options if specified.
10) Seek into proper location of data file for quote (determined
from location read from index file).
11) Read and display quote.
12) Update index file with next quote to be displayed location.
13) Close files.
See PROCEDURE DisplayHelp for more information about options available
and the data file format.
See PROCEDURE UpdateIndexFile for information on the format of the
index file(s).
NOTE: this program is not very modular due to the speed factor. I wanted
to make this as fast as possible without adding much assembly code
and still have sufficient error-checking. Too many procedures
would have slowed it down (I timed it). So, please excuse this
programming oversight; it was done for speed. However, you will
notice I could have been LESS modular; code size was a factor, too.
UTTER.PAS was written and compiled using TURBO PASCAL 6.0 and tested
on a variety of Personal Computers, from 8086s to 80486s.
If you find ANY bugs, or have any suggestions or ideas I'd be happy to
hear from you. Please don't hesitate to contact me for any information.
I have more utilites in the works, all DOS-based. Here's my address:
Jody R. Cairns
P.O. Box 5991
St. John's, NF
Canada
A1C 5X4
e-mail: jodyc@cs.mun.ca
*)
(* Compiler directives follow: *)
{$M 5120,0,0} (* Memory requirements: 5 KB for stack, 0 KB for heap *)
{$I-} (* I/O checking off *)
{$R-} (* Range checking off *)
{$S-} (* Stack checking off *)
{$X-} (* Extended syntax off *)
{$V-} (* Strict VAR-string checking off *)
{$B-} (* Short-circuit boolean evaluation *)
{$D-} (* Debug information off *)
{$L-} (* Local debug information off *)
{$E-} (* 8087 emulation off *)
{$N-} (* 8087/80287 code generation off *)
{$G-} (* 80286 code generation off *)
{$F-} (* Force far calls off *)
{$A+} (* Word align data *)
{$O-} (* Overlays not allowed *)
USES
DOS, CRT;
LABEL
EndLoop1, (* Used for goto statements *)
EndLoop2;
CONST
Title = 'UTTER 1.0, Copyright (c) 1994, Jody R. Cairns';
EndOfQuote = '~'; (* End of quote indicator *)
IndexExt = '.IDX'; (* extension of index file *)
ESC = #27; (* ASCII code for <ESC> key *)
BufferSize = 1024 * 61; (* Maximum size of buffer *)
MaxWord = 65535; (* Largest possible word value *)
MaxSeconds = 60; (* Maximum # of seconds for /P option *)
TYPE
NumStr = string[11]; (* Longint type converted to string *)
IDXFile = file of longint; (* Format of index file *)
BufferType = ARRAY[1..BufferSize] OF char; (* Buffer used for reading quotes *)
CONST
UpdateFile : boolean = FALSE; (* Update index file *)
ShowNumber : boolean = FALSE; (* Show number of quotes in quote file *)
GetRandom : boolean = FALSE; (* Get random quote from quote file *)
TitleNotShown: boolean = TRUE; (* Program name has been displayed *)
InvokeEditor : boolean = FALSE; (* Invoke editor to edit file of quotes *)
DoPrompts : boolean = TRUE; (* Display warning prompts *)
KeyPause : boolean = FALSE; (* Pause with key prompt after quote *)
MousePause : boolean = FALSE; (* Pause with mouse prompt after quote *)
Pause : boolean = FALSE; (* Pause for some seconds after quote *)
Editor : PathStr = 'EDIT'; (* Default editor name *)
CurrRow : byte = 0; (* Current row number of screen *)
PauseMilSecs : word = 2000; (* # of milliseconds to pause for /P *)
Prompt : ComStr = #13#10'Press any key to continue...';
VAR
DataFile : file; (* File containing quotes *)
IndexFile : IDXFile; (* Index file for DataFile *)
Buffer : BufferType; (* Buffer used for reading in quotes *)
Dir : DirStr; (* Directory that contains UTTER.EXE *)
Name : NameStr; (* Name of executing program *)
Ext : ExtStr; (* Extension of file that contains quotes *)
TmpStr, (* Used for option /P[x] -> converted number *)
Param : ComStr; (* Paramater on command-line *)
EditorPath, (* Full path name of editor *)
DataPath : PathStr; (* Full PATH location of file that contains quotes *)
LongIntVar, (* Used for the /P option in val procedure *)
DataTime, (* Current time stamp of file containing quotes *)
OldDataTime, (* Old time stamp of file containing quotes *)
StartPos : longint; (* Index of quotes in Datafile *)
RecsRead, (* # of records (chars) read into Buffer *)
I, J, (* Indices and other stuff *)
Code : word; (* Temporary storage *)
Ch : char; (* Character pressed during prompt *)
NumRows : byte; (* Number of rows on screen *)
Reg : registers; (* CPU registers *)
(*****************************************************************************)
(*****************************************************************************)
FUNCTION KeyPressed: boolean; assembler;
(* Returns TRUE if a key is pressed. *)
ASM
mov ah, 11h (* Report whether character is ready *)
int 16h (* Call Keyboard function *)
mov al, 0 (* Assume FALSE *)
jz @Done (* Zero flag set? Yes, then no input *)
inc